package com.yutel.phone.juny.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;

public class IncomingCallReceiver extends BroadcastReceiver {
	private static String TAG = "IncomingCallReceiver";

	@Override
	public void onReceive(Context context, Intent intent) {
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(context);
		if (prefs.getBoolean("callenabled", false)) {
			String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
			String number = intent
					.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
			String call = prefs.getString("calladdress", "");
			Log.i(TAG, "state=" + state + ",number=" + number);
			// Check phone state
			if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
				if (call.indexOf(number) >= 0) {
					context.startService(new Intent(context,
							IncomingCallIntentService.class));
				}
			}
		}
	}
}
